package Practice6_Internet.P3_UDP;

import Utils.data.DataProcessUtils;
import Utils.web.UdpUtils;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class PracticeTest01 {
    /**
     * 发送端
     */
    @Test
    public void sender() throws IOException {
        try (DatagramSocket socket = new DatagramSocket();) {
            String str = "我是UDP方式发送的导弹";
            UdpUtils.senderSendMessageToReceiver(str, socket, InetAddress.getLocalHost(), 9090);
        }
    }

    /**
     * 接收端
     */
    @Test
    public void receiver() throws IOException {
        try (DatagramSocket socket = new DatagramSocket(9090)) {
            byte[] bytes1 = UdpUtils.receiverReceiveDataFromSender_Bytes(socket, 8 * 1024);
            System.out.println(DataProcessUtils.Bytes2String(bytes1));
        }
    }
}
